package com.magist.manage.web.exception;


import com.magist.core.entity.ResultMessage;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.session.UnknownSessionException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)//此处声明需要捕获Exception类
    @ResponseBody
    public Object handle(Exception e){
        e.printStackTrace();
        ResultMessage resultMessage = ResultMessage.error(e.getMessage());
        if(e instanceof UnknownSessionException){
//            resultMessage.setMessage("session id 不存在");
            resultMessage.setMessage("操作超时,请重新登陆");
        } else if(e instanceof AuthenticationException){
            resultMessage.setMessage(e.getCause().getMessage());
        }
        return resultMessage;
    }

}
